package com.example.desinger.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.example.desinger.common.R;
import com.example.desinger.entity.Interfiles;
import com.example.desinger.entity.StuHomeWork;
import com.example.desinger.service.InterfilesService;
import com.example.desinger.service.StuHomeWorkService;
import jakarta.websocket.server.PathParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/interfiles")
@RestController
public class InterfilesController {
    @Autowired
    private InterfilesService interfilesService;
    @Autowired
    private StuHomeWorkService stuHomeWorkService;

    /**
     * 添加学生标签
     *
     * @param interfiles 数据类
     * @return
     */
    @PostMapping
    public R<String> addInterfiles(@RequestBody Interfiles interfiles) {
        LambdaQueryWrapper<Interfiles> interfi = new LambdaQueryWrapper<>();
        interfi.eq(Interfiles::getStudId, interfiles.getStudId()).eq(Interfiles::getNickname, interfiles.getNickname());
        Interfiles one = interfilesService.getOne(interfi);
        if (one != null) {
            return R.error("这个标签已经创建,不要重复创建！");
        }
        boolean save = interfilesService.save(interfiles);
        if (save) {
            return R.success("标签添加成功！！");
        }
        return R.error("标签添加失败！");
    }

    @GetMapping()
    public R<List<Interfiles>> findAll(@PathParam("stuId") int stuId) {
        LambdaQueryWrapper<Interfiles> lambdaQueryWrapper = new LambdaQueryWrapper();
        lambdaQueryWrapper.eq(Interfiles::getStudId, stuId);
        List<Interfiles> list = interfilesService.list(lambdaQueryWrapper);
        return R.success(list, "查询成功！！你所有的标签如下：");
    }

}
